/*
 * FileReader.java
 * @author Andrey Tesler
 * Created for DiffView project
 * Created on 4 October 2009, 13:56
 */

package diffview;

import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class FileReader {
    
    String fileName;
    
    public FileReader(String fileName) {
        this.fileName = fileName;
    }
    
    /**
     * Reads only first 2 Gb of the file.
     */
    public String read() throws IOException {
        File file = new File(fileName);
        BufferedReader reader 
                = new BufferedReader(new java.io.FileReader(file));
        long fileLength = file.length();
        int arrayLength = (fileLength > Integer.MAX_VALUE 
                ? Integer.MAX_VALUE
                : (int) fileLength);
        char[] chars = new char[arrayLength];
        reader.read(chars);
        return new String(chars);
    }
}
